Its a best practice to avoid hardcoding of text strings in Apex. Ideally those text should be stored in a Custom Label and referenced via those in
the code. This enables administrators and translators to update the messages without modifying the code. It also enables the translation of those text
in international organizations.
This rule raises an issue when a call to the sObject.addError
method is given a hardcoded string.
Noncompliant code example
public class MyClass{
public static myMethod(Case mycase) {
mycase.addError('This is a hardcoded error');
}
}
Compliant solution
public class MyClass{
public static myMethod(Case case) {
mycase.addError(System.Label.caseErrorMessage);
}
}